﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.ComponentModel;

namespace BigWoo.Apps.CertToolLib
{
    /// <summary>
    /// Our encapsulation of Certificate data
    /// </summary>
    public class CertificateData : INotifyPropertyChanged
    {
        private StoreNameType _storeName = StoreNameType.NotSet;
        private StoreLocationType _storeLocation = StoreLocationType.NotSet;
        private string _certName = string.Empty;
        private string _subject = string.Empty;
        private string _thumbPrint = string.Empty;
        private string _serialNo = string.Empty;

        public StoreNameType StoreName 
        {
            get { return _storeName; }
            set { _storeName = value; FirePropertyChanged("StoreName");}
        }

        public StoreLocationType StoreLocation
        {
            get { return _storeLocation; }
            set { _storeLocation = value; FirePropertyChanged("StoreLocation"); }
        }

        public string CertName
        {
            get { return _certName; }
            set { _certName = value; FirePropertyChanged("CertName");}
        }

        public string Subject
        {
            get { return _subject; }
            set { _subject = value; FirePropertyChanged("Subject");}
        }

        public string ThumbPrint
        {
            get { return _thumbPrint; }
            set { _thumbPrint = value; FirePropertyChanged("ThumbPrint");}
        }

        public string SerialNo
        {
            get { return _serialNo; }
            set { _serialNo = value; FirePropertyChanged("SerialNo");}
        }

        public override string ToString()
        {
            StringBuilder str = new StringBuilder();

            str.AppendFormat("\r\nStore: {0}", StoreName);
            str.AppendFormat("\r\nLocation: {0}", StoreLocation);
            str.AppendFormat("\r\nCertificate Name: {0}", CertName);
            str.AppendFormat("\r\nSubject: {0}", Subject);
            str.AppendFormat("\r\nThumb Print: {0}", ThumbPrint);
            str.AppendFormat("\r\nSerial #: {0}", SerialNo);

            return str.ToString();
        }

        #region INotifyPropertyChanged Members
        /// <summary>
        /// 
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="propertyName"></param>
        private void FirePropertyChanged(string propertyName)
        {
            if (null != PropertyChanged)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
        #endregion
    }

    /// <summary>
    /// 
    /// </summary>
    public class CertificateDataCollection : ObservableCollection<CertificateData> { }
}
